#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

#define MAXN 100

typedef struct SNode* PtrToSNode;
typedef enum { ret, lc, lbrc, lbrkt, lpr, rc, rbrc, rbrkt, rpr, others } Token;
typedef Token ElementType;
struct SNode {
    ElementType* Data;
    int Top;
    int Maxsize;
};
typedef PtrToSNode Stack;
Stack CreateStack ( int Maxsize ) {
    Stack S = (Stack)malloc(sizeof(struct SNode));
    S->Data = (ElementType*)malloc(Maxsize*sizeof(ElementType));
    S->Top = -1;
    S->Maxsize = Maxsize;
    return S;
}
bool StackEmpty ( Stack S ) {
    return ( S->Top == -1 );
}
ElementType Peek ( Stack S ) {
    if ( StackEmpty(S) ) {
        printf("Stack Empty\n");
        exit(-1);
    }
    return ( S->Data[S->Top] );
}
bool StackFull ( Stack S ) {
    return ( ( S->Top + 1 ) == S->Maxsize );
}
void Pop ( Stack S ) {
    ( S->Top )--;
}
void Push ( Stack S, ElementType X ) {
    if ( StackFull(S) ) {
        printf("Stack Full\n");
        exit(-2);
    }
    S->Data[++(S->Top)] = X;
}
bool IsEnd ( int newline, char* c );
Token GetToken ( char c );
bool IsPaired ( Token t1, Token t2 );
void PrintS ( Token t );
int Check ( Token* T1, Token* T2 );

int main () {
    Token T1, T2;
    int error = Check(&T1,&T2);

    if ( !error ) printf("YES\n");
    else {
        printf("NO\n");
        switch (error) {
        case 1: 
            printf("?-");
            PrintS(T1);
            break;
        case 2:
            PrintS(T2);
            printf("-?");
            break;
        default:break;
        }
        printf("\n");
    }
    return 0;
}

bool IsEnd ( int newline, char* c ) {
    if ( newline && ((*c) == '.') ) {
        scanf("%c",c);
        if ( (*c) == '\n' ) return true;
        else return false;
    }
    else return false;
}
Token GetToken ( char c ) {
    switch (c) {
    case '\n': return ret;
    case '{':  return lbrc;
    case '[':  return lbrkt;
    case '(':  return lpr;
    case '/':
        scanf("%c",&c);
        if ( c == '*' ) return lc;
        else return GetToken(c);
    case '}':  return rbrc;
    case ']':  return rbrkt;
    case ')':  return rpr;
    case '*':
        scanf("%c",&c);
        if ( c == '/' ) return rc;
        else return GetToken(c);
    default:   return others;
    }
}
bool IsPaired ( Token t1, Token t2 ) {
    return ( t1 - t2 ) == 4;
}
void PrintS ( Token t ) {
    switch (t) {
    case lc:    printf("/*"); break;
    case lbrc:  printf("{");  break;
    case lbrkt: printf("[");  break;
    case lpr:   printf("(");  break;
    case rc:    printf("*/"); break;
    case rbrc:  printf("}");  break;
    case rbrkt: printf("]");  break;
    case rpr:   printf(")");  break;
    default:    break;
    }
}
int Check ( Token* T1, Token* T2 ) {
    Stack S = CreateStack(MAXN);
    char c;
    Token t;
    int newline = 1, error = 0;
    while (1) {
        scanf("%c",&c);
        if ( IsEnd(newline,&c) ) break;
        else {
            switch (t = GetToken(c)) {
                case lc:    
                case lbrc:  
                case lbrkt: 
                case lpr:   Push(S,t);newline = 0; break;
                case rc:    
                case rbrc:  
                case rbrkt: 
                case rpr:
                    if (StackEmpty(S)) error = 1;
                    else if (!IsPaired(t,Peek(S))) error = 2; 
                    else Pop(S);
                    newline = 0;
                    break;
                case ret: newline = 1; break;
                default:  newline = 0; break;
            }
            if (error) break;
        }
    }
    if ( !error && !StackEmpty(S) ) error = 2;
    (*T1) = t;
    (*T2) = Peek(S);
    return error;
}